<?php
namespace Act\Os;
use \Lib\ErrorMessage;
use \Lib\Common;
use \Lib\Page;
class Quicknotes extends Backend{
	public function doGet(){
		$quicknote_mod = model('#QuickNote','adm_');
		$count = $quicknote_mod->searchCount();
		$page = new Page($count,self::PAGE_SIZE);
		$quicknotes = $quicknote_mod->getNotes($page->offset,$page->size);

		$this->display('index.php',array(
			'page_no' => $page->page_no,
			'page_size' => self::PAGE_SIZE,
			'page_html' => $page->show(),
			'quicknotes' => $quicknotes,
			'admin_action_confirm'  => Common::renderJsConfirm("icon-remove"),
			'user_group' => session('user_info')['user_group'] ,
			'current_user_id' => session('uid'),
		));
	}

	public function doDelete(){
		$note_id = get('note_id',0,'absint');
		$this->checkParam($note_id);
		$quicknote_mod = model('#QuickNote','adm_');
		$note = $quicknote_mod->getNoteById($note_id);
	
		//是超级管理员组的成员或者是quicknote的主人
		if(session('user_info')['user_group'] ==1 || $note['owner_id'] == session('uid')){
			$result = $quicknote_mod->delNote ( $note_id );
			if ($result>0) {
				$this->sysLog(session('user_info')['user_name'], 'DELETE', 'QuickNote',$note_id, json_encode($note) );
				return $this->success ('便签删除成功','os/quicknotes');
			}else{
				return $this->error("error",'os/quicknotes');
			}
		}else{
			return $this->error(ErrorMessage::QUICKNOTE_NOT_OWNER,'os/quicknotes');
		}
	}
}